home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / java_Win / demo / NervousText / NervousText.class (.txt) < prev    next >
Encoding:
Java Class File  |  1995-10-12  |  2.2 KB  |  76 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Event;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6.  
  7. public class NervousText extends Applet implements Runnable {
  8.    char[] separated;
  9.    // $FF: renamed from: s java.lang.String
  10.    String field_0;
  11.    Thread killme;
  12.    // $FF: renamed from: i int
  13.    int field_1;
  14.    int x_coord;
  15.    int y_coord;
  16.    String num;
  17.    int speed = 35;
  18.    int counter;
  19.    boolean threadSuspended = false;
  20.  
  21.    public void init() {
  22.       ((Component)this).resize(150, 50);
  23.       ((Component)this).setFont(new Font("TimesRoman", 1, 36));
  24.       this.field_0 = ((Applet)this).getParameter("text");
  25.       if (this.field_0 == null) {
  26.          this.field_0 = "HotJava";
  27.       }
  28.  
  29.       this.separated = new char[this.field_0.length()];
  30.       this.field_0.getChars(0, this.field_0.length(), this.separated, 0);
  31.    }
  32.  
  33.    public void start() {
  34.       if (this.killme == null) {
  35.          this.killme = new Thread(this);
  36.          this.killme.start();
  37.       }
  38.  
  39.    }
  40.  
  41.    public void stop() {
  42.       this.killme = null;
  43.    }
  44.  
  45.    public void run() {
  46.       for(; this.killme != null; ((Component)this).repaint()) {
  47.          try {
  48.             Thread.sleep(100L);
  49.          } catch (InterruptedException var1) {
  50.          }
  51.       }
  52.  
  53.       this.killme = null;
  54.    }
  55.  
  56.    public void paint(Graphics g) {
  57.       for(this.field_1 = 0; this.field_1 < this.field_0.length(); ++this.field_1) {
  58.          this.x_coord = (int)(Math.random() * (double)10.0F + (double)(15 * this.field_1));
  59.          this.y_coord = (int)(Math.random() * (double)10.0F + (double)36.0F);
  60.          g.drawChars(this.separated, this.field_1, 1, this.x_coord, this.y_coord);
  61.       }
  62.  
  63.    }
  64.  
  65.    public boolean mouseDown(Event evt, int x, int y) {
  66.       if (this.threadSuspended) {
  67.          this.killme.resume();
  68.       } else {
  69.          this.killme.suspend();
  70.       }
  71.  
  72.       this.threadSuspended = !this.threadSuspended;
  73.       return true;
  74.    }
  75. }
  76.